;********************* Real mode ******************
%define DISK_FLOPPY 0
%define DISK_HDD 	0x80
%define SECT_SZ		512
%define NSEC 10
%define MBR_MAGIC 	0aa55h	
%define PRT_START	1beh
%define PART_TYPE 	0x70 ;my part type
%define SECT_SHIFT 9
%define NMAX_LDR_SECTS 0feh
%define LOADER_CHS 2
%define MAX_CHSINTS_SZ 400*4
%define LOADER2_CHS (1<<8) +1 ;cyl 1,sec 1
%define MBR_CHS 1
%define READ_TRYES 10

;********************* _Protected mode ******************

;*** CR0
%define CR0_PE	1<<0 ;0(on reset);0:real mode, 1:protected(only segments protection) 
%define CR0_MP	1<<1 ;0;1: FPU exist
%define CR0_EM	1<<2 ;0;1: FPU exist
%define CR0_TS	1<<3 ;0;1: auto settled when task switched
%define CR0_ET	1<<4 ;1;1: on P4,Xeon,P6; 
%define CR0_NE	1<<5 ;0;for FPU error reporting
%define CR0_WP	1<<16 ;0;1: supervisor cant write to RD-only pages; 0:allow write
%define CR0_AM	1<<18 ;0;1:alignment checking(cpl=3,PM or V86,EFLAGS_AC=1);0:no check
%define CR0_NW	1<<29 ;1;0:enable Write-Back(>Pentium) or Wr-Througth(intel 486) (CR0_CD=0)
%define CR0_CD	1<<30 ;1;1: disable L1 cache; 0: enable 
%define CR0_PG	1<<31 ;0;1: paging enabled (CR0_PE=1); 0: paging disabled

;*** EFLAGS
%define EFL_TF	1<<8  ; ;1:trap mode for debuging(int 1);
%define EFL_IF	1<<9  ; ;0:disable CPU reaction on non-NMI hardware ints 
%define EFL_DF	1<<10	; 1: esi,edi decreased;direction of scasb/lodsb/etc...
%define EFL_IOPL	(1<<12 | 1<<13)  ; ;IOPL level
%define EFL_NT	1<<14  ; ;nested tasks
%define EFL_RF	1<<16  ; ;resume
%define EFL_VM	1<<17  ; ;1:v86 mode to enabled; 0:to disable
%define EFL_AC	1<<18  ; ;1:alignment checking
%define EFL_VIF	1<<19  ; ;copy of EFL_IF,used when(CR4_VME=1 or CR4_PVI=1) and IOPL < 3
%define EFL_VIP	1<<20  ; ;1:virtual int is pending
%define EFL_ID	1<<21  ; ; CPUID is supported if this flag can be changed

;*** Segment types (IA32)
%define SEG_DESC_TYPE		(1 << 12) ;0:sys;1:coomon (code,data)
%define SEG_SYS_AVAIL 	(1 << 9 )  ;0:availible; 1:busy ;for TSS16,TSS32
%define SEG_SYS_BITNESS (1 << 11)  ;0:16bit; 1: 32bit ;for call gate,TSS.

;*sys
%define SEG_TSS16A 		(1 << 8) ;16-bit TSS, availible
%define SEG_LDT 		(2 << 8) ;LDT
%define SEG_TSS16B 		(3 << 8) ;16-bit TSS, busy
%define SEG_RSRV 		(4 << 8) ;16-bit Call gate
%define SEG_RSRV 		(5 << 8) ;Task gate
%define SEG_RSRV 		(6 << 8) ;16-bit Int gate
%define SEG_RSRV 		(7 << 8) ;16-bit Trap gate
%define SEG_RSRV 		(9 << 8)  ;32-bit TSS, availible
%define SEG_RSRV 		(11 << 8) ;32-bit TSS, busy
%define SEG_RSRV 		(12 << 8) ;32-bit Call gate
%define SEG_RSRV 		(14 << 8) ;32-bit Int gate
%define SEG_RSRV 		(15 << 8) ;32-bit Trap gate

;*code/data
%define SEG_NONSYS_CODE			(1 << 11)  ;1:code;0:data
%define SEG_DATA_ACC			(1 <<  8)  ;1:accessed; (settled when seg.reg. is loaded with this sel)
%define SEG_DATA_RW			    (1 <<  9)  ;1:read/write; 0:read-only
%define SEG_DATA_STK			(1 << 10)  ;1:expand-down seg(stack); 0:expand-up(common data)

%define SEG_CODE_ACC			(1 <<  8)  ;1:accessed; (settled when seg.reg. is loaded with this sel)
%define SEG_CODE_RE			    (1 <<  9)  ;1:read/exec; 0:exec-only
%define SEG_CODE_CNF			(1 << 10)  ;1:conform seg(inherit CPL: user->kernel_cnf); 0:non-conform
;NOTE: conforming: divide,overflow exceptions; non-conforming: isolated from buggy r3 code sys procedures 
;NOTE: kernel->user by call or jmp : #GP, regardless of conforming.
;NOTE: for data seg. - opposite logic: (user->kernel_data) = #GP; (kernel->user_data) = OK


;*** System tables
;NOTE: GDT must be at least 1 -it's not in segment; if LDTs exist - each is in separate seg;




;################## MACROSES 
;###### seg descriptor macroses (edx|eax)->%1_32bit
%macro gdesc_limit 1
mov %1,eax
and %1,0xffff
%endmacro

%macro gdesc_base 1
mov %1,eax
shr %1,16
push edx
ror edx,8
ror edx,16
xchg dl,dh
shl edx,16
add %1,edx
pop edx
%endmacro

%macro GDTR 1
%1.lim dw 0
%1.adr dd 0
%endmacro

%macro IDTR 1
%1.lim dw 0
%1.adr dd 0
%endmacro

%macro LDTR 1
%1.sel dw 0
%endmacro

%macro TR 1
%1.sel dw 0
%endmacro